Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix:nil pointer #959

Closed
wants to merge 1 commit into from
Closed

Fix:nil pointer #959

wants to merge 1 commit into from

Conversation

shnpd
Copy link

@shnpd shnpd commented Oct 28, 2024

Error when spending an already used UTXO: “runtime error: invalid memory address or nil pointer dereference”

According to my observation, in btcwallet/rpc/legacyrpc/methods.go:1716 the call to hex.DecodeString(result.ScriptPubKey.Hex) with the parameter “result” is nil. This is because when calling resp.Receive() on line 1712, if you use a spent UTXO, it will return (nil,nil), so need to handle the error if result is nil.

Copy link
Collaborator

@guggero guggero left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the fix. Linter is not happy though.

@@ -1713,6 +1713,9 @@ func signRawTransaction(icmd interface{}, w *wallet.Wallet, chainClient *chain.R
if err != nil {
return nil, err
}
if result == nil {
return nil, errors.New("the utxo has been spent")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: the linter wants you to define this error as a package-level variable. So just add it to the top of the file with a name like errUtxoSpent and use it here.

@guggero
Copy link
Collaborator

guggero commented Dec 9, 2024

Replaced by #969 (commit author attribution preserved).

@guggero guggero closed this Dec 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants